﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SAM.Framework.BasicExtends
{
    public static class StringExtends
    {
        /// <summary>
        /// 将指定字符串转换为长整型的IpAddress
        /// </summary>
        /// <param name="ips">字符串类型的ip地址，如：127.0.0.1, 192.168.0.8 etc</param>
        /// <returns></returns>
        public static System.Net.IPAddress ConvertToIp(this string ostring)
        {
            char[] separator = new char[] { '.' };
            string[] items = ostring.Split(separator);
            long longIp = long.Parse(items[3]) << 24
                    | long.Parse(items[2]) << 16
                    | long.Parse(items[1]) << 8
                    | long.Parse(items[0]);
            return new System.Net.IPAddress(longIp); 
        }
    }
}
